Ext.namespace('VAS');

VAS.AdvancedSearchGridPanel = Ext.extend(Ext.grid.GridPanel, {
	initComponent : function() {
		var _this=this;		
		_this.cm  = new Ext.grid.ColumnModel(
			[
				new Ext.grid.RowNumberer(),
		        new Ext.grid.CheckboxSelectionModel({
					defaults : {
						sortable : true											
					}
				}),
		        {
			        header: '搜索条件',
			        width: 200,
			        dataIndex: 'name'
			    }
		    ]
		);		
		var ds = new Ext.data.Store({
			autoLoad : true,
			url : 'admin/view/cfg!getViewPanelFilterByGridPanelId.action?gridPanelId='+this.gridPanelId+'&entryMenuId='+this.menuid,
			reader : new Ext.data.JsonReader({
				
			}, [
				{name: 'id'},
				{name: 'viewpanelid'},
				{name: 'name'},
				{name: 'tips'},
				{name: 'filter'},
				{name: 'version'}
			])
		});	 
		_this.tb = new Ext.Toolbar({
		    items: [
		        '->', // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill
		        '-',
		        {
					xtype : 'dynamicTbar',
					text : '删除',
					action : 'admin/view/cfg!deleteViewPanelFilter.action',
					iconCls : 'icon_delete',
					actionType : 'delete'
		        }
		    ]
		});
		_this.sm = new Ext.grid.CheckboxSelectionModel({
			defaults : {
				sortable : true											
			}
		});
		
		var config = {
			viewConfig : {
				forceFit : true
			},
			store	:	ds,
			cm:_this.cm,
			enableColLock : false,
			loadMask : true,
			border : false,
			stripeRows : true,
			tbar	: _this.tb,
			sm		: _this.sm,
			listeners : {
				rowdblclick : function(_this,rowIndex,e){
					var record = ds.getAt(rowIndex);
					var formPanel = Ext.getCmp('advancedSearch_formPanel');
					//把搜索条件复制到record的data中，使搜索条件在form中显示。
					Ext.apply(record.data,record.data.filter);
					formPanel.getForm().reset();
					formPanel.getForm().loadRecord(record);
				}
			}
		};
			
		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);
		VAS.AdvancedSearchGridPanel.superclass.initComponent.apply(this, arguments);
	}
	
	,getView : function(){
        if(!this.view){
        	Ext.apply(this.viewConfig,{
            	sortAscText : '升序排列',
            	sortDescText : '降序排列',
            	columnsText : '列'
            });
            this.view = new Ext.grid.GridView(this.viewConfig);
        }
        return this.view;
    }
});
Ext.reg('advancedSearchGridPanel',VAS.AdvancedSearchGridPanel);
